#! /usr/bin
#-*- coding:utf-8 -*-

__author__ = 'Michael'

from convert import srcConverter
import re

class post:
    def __init__(self, log, title, content, tagText, categories):
        self.__log = log
        self.__title = title
        self.__content = content
        self.__tagText = tagText
        self.__categories = categories
        self.__seoPattern  = re.compile(r'[\'"\s]')
        

    def getTitle(self):
        return self.__title
    
    
    def getContent(self):
        con = srcConverter(self.__log)
        self.__content = con.doConvert(self.__content)

        return self.__content
    

    def getTags(self):
        if not self.__tagText:
            return []
        return self.__tagText.split(',')
    

    def getCategory(self):
        if not self.__categories:
            return []
        return self.__categories.split('/')
    

    def getSeoTitle(self):
        """
        replace char like ' " <space> & chinese -> _
        """
        
        self.__log.debug("generate seo title from %s" % self.__title)
        return re.sub(self.__seoPattern, self.__match2underline, self.__title)


    def __match2underline(self, matchObj):
        return "_"